package fourfaith.com.ff_sl21_app.weather;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

/**
 * 获取当前时间和星期几
 * @author administrator
 *
 */
public class DateUtil {
	 private static String mYear;
     private static String mMonth;
     private static String mDay;
     private static String mWay;
     /**
      * 获取当前时间
      * @return
      */
    public static String currDate(){
       final Calendar c = Calendar.getInstance();
       c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
       mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
       mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
       mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码
       return mYear + "年" + mMonth + "月" + mDay+"日";
   }
    /**
     * 获取星期几
     */
    public static String currWeek(){
    	 final Calendar c = Calendar.getInstance();
         c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
         mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
         if("1".equals(mWay)){  
             mWay ="天";  
         }else if("2".equals(mWay)){  
             mWay ="一";  
         }else if("3".equals(mWay)){  
             mWay ="二";  
         }else if("4".equals(mWay)){  
             mWay ="三";  
         }else if("5".equals(mWay)){  
             mWay ="四";  
         }else if("6".equals(mWay)){  
             mWay ="五";  
         }else if("7".equals(mWay)){  
             mWay ="六";  
         } 
         return"星期"+mWay; 
    }
    
    // 将字符串转为时间戳
    @SuppressLint("SimpleDateFormat")
    public static long getTime(String time) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
    	try {
    		long timestamp = sdf.parse(time).getTime();
    		return (timestamp/1000);
    	} catch (ParseException e) {
    		e.printStackTrace();
    	}
    	return 0;
    }
}
